package com.bionic.banking.core.entity;

import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

public class Country {

    private String iso;
    private String code;
    private String name;

    public Country(String iso, String code, String name) {
        this.iso = iso;
        this.code = code;
        this.name = name;
    }

    public String getCode() {
        return code;
    }
    private static List<Country> countries = null;

    public static List<Country> getCountries() {

        if (countries == null) {
            countries = new ArrayList<>();

            String[] isoCountries = Locale.getISOCountries();
            for (String country : isoCountries) {
                Locale locale = new Locale("en", country);
                String iso = locale.getISO3Country();
                String code = locale.getCountry();
                String name = locale.getDisplayCountry();

                if (!"".equals(iso) && !"".equals(code)
                        && !"".equals(name)) {
                    countries.add(new Country(iso, code, name));
                }
            }
        }
        return countries;
    }

    @Override
    public String toString() {
        return name;
    }
}